--License
--	This file is part of AssTermo.
--
--    AssTermo is free software: you can redistribute it and/or modify it
--    under the terms of the GNU General Public License as published by
--    the Free Software Foundation, either version 3 of the License, or
--    (at your option) any later version.
--
--    AssTermo is distributed in the hope that it will be useful, but WITHOUT
--    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
--    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
--    for more details.
--
--    You should have received a copy of the GNU General Public License
--    along with AssTermo.  If not, see <http://www.gnu.org/licenses/>.
--
--Description
--    Graphics File
--    Some Parts of this file were withdrawn from BetterLua API.
--    Many thanks to their authors.


gc=platform.gc()

--BetterLua API
local function test(arg)
	return arg and 1 or 0
end

local function screenRefresh()
	return platform.window:invalidate()
end

local function pww()
	return platform.window:width()
end

local function pwh()
	return platform.window:height()
end

local function verticalBar(x)
	myGC:fillRect(x,0,1,platform.window:height())
end

local function horizontalBar(y)
	myGC:fillRect(0,y,platform.window:width(),1)
end
local function drawSquare(x,y,l)
	myGC:drawPolyLine({(x-l/2),(y-l/2), (x+l/2),(y-l/2), (x+l/2),(y+l/2), (x-l/2),(y+l/2), (x-l/2),(y-l/2)})
end
local function drawPoint(x, y)
	myGC:fillRect(x, y, 1, 1)
end
local function drawCircle(x, y, diameter)
	myGC:drawArc(x - diameter/2, y - diameter/2, diameter,diameter,0,360)
end

local function drawCenteredString(str)
	myGC:drawString(str, (pww() - myGC:getStringWidth(str)) / 2, pwh() / 2, "middle")
end

local function drawXCenteredString(str,y)
	myGC:drawString(str, (pww() - myGC:getStringWidth(str)) / 2, y, "top")
end
Color = {
	["black"] = {0, 0, 0},
	["red"] = {0xff, 0, 0},
	["green"] = {0, 0xff, 0},
	["blue "] = {0, 0, 0xff},
	["white"] = {0xff, 0xff, 0xff},
	["brown"] = {165,42,42},
	["cyan"] = {0,255,255},
	["darkblue"] = {0,0,139},
	["darkred"] = {139,0,0},
	["fuchsia"] = {255,0,255},
	["gold"] = {255,215,0},
	["gray"] = {127,127,127},
	["grey"] = {127,127,127},
	["lightblue"] = {173,216,230},
	["lightgreen"] = {144,238,144},
	["magenta"] = {255,0,255},
	["maroon"] = {128,0,0},
	["navyblue"] = {159,175,223},
	["orange"] = {255,165,0},
	["palegreen"] = {152,251,152},
	["pink"] = {255,192,203},
	["purple"] = {128,0,128},
	["royalblue"] = {65,105,225},
	["salmon"] = {250,128,114},
	["seagreen"] = {46,139,87},
	["silver"] = {192,192,192},
	["turquoise"] = {64,224,208},
	["violet"] = {238,130,238},
	["yellow"] = {255,255,0}
}
local function setColor(theColor)
	if type(theColor) == "string" then
		theColor = string.lower(theColor)
		if type(Color[theColor]) == "table" then myGC:setColorRGB(unpack(Color[theColor])) end
	elseif type(theColor) == "table" then
		myGC:setColorRGB(unpack(theColor))
	end
end
---end of BetterLua API thanks to Adriweb
local function drawCenteredRect(x0,y0)
	local pos={x0=math.floor(pww()-x0/2),y0=math.floor(pwh()-y0/2)}
	myGC:drawRect(pos.x0,pos.y0,size.x0,size.y0)
end

function Text(title,content)
	h1=gc:getStringHeight(title)
	w1=gc:getStringWidth(title)
	h2=gc:getStringHeight(content)
	w2=gc:getStringWidth(content)
	h=h1+h2
	if w1>w2 then
		w=w1
		else
		w=w2
	end
	window(w,h)
	gc:setColorRGB(200,200,200)
	gc:drawString(title,x+(w-w1)/2,y+math.floor(h1/2),"middle")
	gc:setColorRGB(0,0,0)
	gc:drawString(content,x+(w-w2)/2,y+h1+math.floor(h2/2),"middle")
end
function window(x,y)
	local size={x=x>=60 or 60,y=y>=100 or 100}
	if size.x<60
	or size.y<100 then
		error("Size is too small for window()")
	elseif size.x>pww() or size.y>pwh() then
		error("Size is too big for window()")
	end
	position={x=math.floor((pww()-size.x)/2),y=math.floor((pwh()-size.y)/2)}
	setColor("silver")
	gc:fillRect(position.x,position.y,w,h+k)
	setColor("black")
	gc:fillRect(x,y,w,k)
	gc:setPen("thin","smooth")
	if true then
	end
end
function on.paint(gc)
	myGC=gc
	Text("Esta mesmo assim","ok")
end
--End of Graphics File
